package com.ruoyi.system.service.impl;

import java.math.BigDecimal;
import java.util.List;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.system.domain.ProjectVo;
import com.ruoyi.system.service.ITPurchaseService;
import com.ruoyi.system.service.ITReceiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BdProjectclassMapper;
import com.ruoyi.system.service.IBdProjectclassService;

/**
 * 项目Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-16
 */
@Service
public class BdProjectclassServiceImpl implements IBdProjectclassService 
{
    @Autowired
    private BdProjectclassMapper bdProjectclassMapper;
    @Autowired
    private ITPurchaseService itPurchaseService;
    @Autowired
    private ITReceiveService itReceiveService;

    @Override
    @DataSource(value = DataSourceType.YONGYOU)
    public List<ProjectVo> getProject() {
        List<ProjectVo> project = bdProjectclassMapper.getProject();
        for (ProjectVo projectVo : project) {
            //将来接口调用获取项目采购领用经费
            projectVo.setPurchaseAmount(new BigDecimal("10000"));
            //获取项目已用采购和领用经费
            projectVo.setReceiveAmount(new BigDecimal("10000"));
            BigDecimal purchaseDisburse = itPurchaseService.getDisburseTotal(projectVo.getPkProjectclass());
            projectVo.setPurchaseDisburse(purchaseDisburse==null?new BigDecimal("0"):purchaseDisburse);
            BigDecimal receiveDisburse = itReceiveService.getDisburseTotal(projectVo.getPkProjectclass());
            projectVo.setReceiveDisburse(receiveDisburse==null?new BigDecimal("0"):receiveDisburse);
            projectVo.setPurchaseBalance(projectVo.getPurchaseAmount().subtract(projectVo.getPurchaseDisburse()));
            projectVo.setReceiveBalance(projectVo.getReceiveAmount().subtract(projectVo.getReceiveDisburse()));
        }
        return project;
    }
}
